package com.mentaleye.dal.dao.mybatis;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.mentaleye.dal.dao.PermissionsDao;
import com.mentaleye.dal.model.Permissions;
import com.mentaleye.dal.model.PermissionsExample;

import com.mentaleye.dal.service.PermissionsMapper;
@Repository
public class PermissionsDaoImpl extends BaseDao implements PermissionsDao{
	
	@Autowired private PermissionsMapper permissionsMapper;

	@Override
	public boolean insertPermissions(Permissions permissions) {
		return getResultByInt(permissionsMapper.insertSelective(permissions));
	}

	@Override
	public boolean updatePermissions(Permissions permissions) {
		return getResultByInt(permissionsMapper.updateByPrimaryKeySelective(permissions));
	}

	@Override
	public boolean deletePermissions(List<Integer> permissionsId) {
		if (permissionsId == null || permissionsId.size() == 0) return false;
		PermissionsExample example=new PermissionsExample();
		example.createCriteria().andPermissionsIdIn(permissionsId);
	    int rows=permissionsMapper.deleteByExample(example);
	    return rows==permissionsId.size();
	}
	
	public boolean deletePermissionsByparentpermissionsId(Integer parentpermissionsId){
		return getResultByInt(permissionsMapper.deleteByParentpermissionsId(parentpermissionsId));
	}

	@Override
	public List<Permissions> queryPermissions(Map<String, Object> map) {
		return permissionsMapper.selectByMap(map);
	}

	@Override
	public List<Permissions> queryPermissions(PermissionsExample example) {
		return permissionsMapper.selectByExample(example);
	}
	 public Permissions queryPermissions(Integer permissionsId){
		 return permissionsMapper.selectByPrimaryKey(permissionsId);
	 }
	 public Permissions queryPermissionsByparentpermissionsId(Integer parentpermissionsId){
		 return permissionsMapper.selectByparentpermissionsId(parentpermissionsId);
	 }

	@Override
	public List<Permissions> queryPermissions(List<Integer> permissionsId) {
		PermissionsExample example=new PermissionsExample();
		example.createCriteria().andPermissionsIdIn(permissionsId);
		return permissionsMapper.selectByExample(example);
	}
	 

	 

}
